/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EditarCliente.java
 *
 * Created on 05/04/2011, 00:13:55
 */
package editar;

import Classe.BD;
import Classe.Bairro;
import Classe.Cidade;
import Classe.Cliente;
import Classe.Endereco;
import Classe.Estado;
import Classe.Validacao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author gladson
 */
public class EditarCliente extends Validacao {

    public EditarCliente() throws SQLException {

        initComponents();
        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

        iniciar();

    }
    int idCli;
    String estad;
    String cid;
    String bai;
    String end;
    Cliente cli;
    Estado estado;
    String selTipo;

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel2 = new javax.swing.JPanel();
        jpnCadastroCliente = new javax.swing.JPanel();
        jpnPessoalCliente = new javax.swing.JPanel();
        lblDataNascCliente = new javax.swing.JLabel();
        lblCpfCliente = new javax.swing.JLabel();
        stxtRgCli = new javax.swing.JTextField();
        lblNomeCliente = new javax.swing.JLabel();
        lblRgCliente = new javax.swing.JLabel();
        lblTelefoneCliente = new javax.swing.JLabel();
        lblCelularCliente = new javax.swing.JLabel();
        lblEmailCliente = new javax.swing.JLabel();
        stxtEmailCli = new javax.swing.JTextField();
        stxtNomeCli = new javax.swing.JTextField();
        stxtCpfCli = new javax.swing.JFormattedTextField();
        stxtDataNascCli = new javax.swing.JFormattedTextField();
        stxtTelCli = new javax.swing.JFormattedTextField();
        stxtCelCli = new javax.swing.JFormattedTextField();
        jpnTipoCliente = new javax.swing.JPanel();
        StxtBomCli = new javax.swing.JRadioButton();
        StxtRegCli = new javax.swing.JRadioButton();
        stxtRuimCli = new javax.swing.JRadioButton();
        lblDataCliente = new javax.swing.JLabel();
        txtDataCadastroCliente = new javax.swing.JTextField();
        btSalvarCli = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        stxtObsCli = new javax.swing.JTextArea();
        jPanel45 = new javax.swing.JPanel();
        btCadasVeiCli = new javax.swing.JButton();
        btSairEditarCli = new javax.swing.JButton();
        jpnEnderecoCliente1 = new javax.swing.JPanel();
        lblCepCliente1 = new javax.swing.JLabel();
        lblEstadoCliente1 = new javax.swing.JLabel();
        lblCidadeCliente1 = new javax.swing.JLabel();
        cbCidade = new javax.swing.JComboBox();
        lblBairroCliente1 = new javax.swing.JLabel();
        cbBairro = new javax.swing.JComboBox();
        lblRuaAvCliente1 = new javax.swing.JLabel();
        cbEndereco = new javax.swing.JComboBox();
        lblNumeroCliente1 = new javax.swing.JLabel();
        ItxtNumCli = new javax.swing.JTextField();
        lblComplementoCliente1 = new javax.swing.JLabel();
        cbEstado = new javax.swing.JComboBox();
        stxtApCli = new javax.swing.JTextField();
        stxtCompCli = new javax.swing.JComboBox();
        cbCep = new javax.swing.JFormattedTextField();
        lblMensagemEndereco = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jpnCadastroCliente.setBackground(new java.awt.Color(255, 255, 255));
        jpnCadastroCliente.setBorder(javax.swing.BorderFactory.createTitledBorder(null, " Editar Cadastro Cliente ", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("PMingLiU", 0, 36))); // NOI18N
        jpnCadastroCliente.setPreferredSize(new java.awt.Dimension(800, 600));

        jpnPessoalCliente.setBackground(new java.awt.Color(255, 255, 255));
        jpnPessoalCliente.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Pessoal", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        lblDataNascCliente.setFont(new java.awt.Font("Arial", 1, 11));
        lblDataNascCliente.setText("Data Nasc.");

        lblCpfCliente.setFont(new java.awt.Font("Arial", 1, 11));
        lblCpfCliente.setText("CPF ");

        stxtRgCli.setFont(new java.awt.Font("Arial", 0, 12));
        stxtRgCli.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        lblNomeCliente.setBackground(new java.awt.Color(204, 204, 204));
        lblNomeCliente.setFont(new java.awt.Font("Arial", 1, 11));
        lblNomeCliente.setText("Nome ");

        lblRgCliente.setFont(new java.awt.Font("Arial", 1, 11));
        lblRgCliente.setText("RG ");

        lblTelefoneCliente.setFont(new java.awt.Font("Arial", 1, 11));
        lblTelefoneCliente.setText("Telefone ");

        lblCelularCliente.setFont(new java.awt.Font("Arial", 1, 11));
        lblCelularCliente.setText("Celular");

        lblEmailCliente.setFont(new java.awt.Font("Arial", 1, 11));
        lblEmailCliente.setText("E-mail");

        stxtEmailCli.setFont(new java.awt.Font("Arial", 0, 12));
        stxtEmailCli.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        stxtNomeCli.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        stxtCpfCli.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        try {
            stxtCpfCli.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        stxtDataNascCli.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        try {
            stxtDataNascCli.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        stxtTelCli.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        try {
            stxtTelCli.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        stxtCelCli.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        try {
            stxtCelCli.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        javax.swing.GroupLayout jpnPessoalClienteLayout = new javax.swing.GroupLayout(jpnPessoalCliente);
        jpnPessoalCliente.setLayout(jpnPessoalClienteLayout);
        jpnPessoalClienteLayout.setHorizontalGroup(
            jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                        .addGroup(jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblTelefoneCliente)
                            .addComponent(stxtTelCli, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblCelularCliente)
                            .addComponent(stxtCelCli, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                                .addComponent(lblEmailCliente)
                                .addGap(252, 252, 252))
                            .addComponent(stxtEmailCli, javax.swing.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)))
                    .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                        .addGroup(jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblNomeCliente)
                            .addComponent(stxtNomeCli, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                                .addComponent(lblCpfCliente)
                                .addGap(93, 93, 93))
                            .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                                .addComponent(stxtCpfCli, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)))
                        .addGroup(jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(stxtRgCli, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblRgCliente))
                        .addGap(18, 18, 18)
                        .addGroup(jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblDataNascCliente)
                            .addComponent(stxtDataNascCli, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jpnPessoalClienteLayout.setVerticalGroup(
            jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                        .addComponent(lblNomeCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(stxtNomeCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                        .addComponent(lblDataNascCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(stxtDataNascCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                        .addComponent(lblCpfCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(stxtCpfCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                        .addComponent(lblRgCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(stxtRgCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblTelefoneCliente)
                    .addGroup(jpnPessoalClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                            .addComponent(lblCelularCliente)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(stxtCelCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(stxtTelCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jpnPessoalClienteLayout.createSequentialGroup()
                            .addComponent(lblEmailCliente)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(stxtEmailCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(46, 46, 46))
        );

        jpnTipoCliente.setBackground(new java.awt.Color(255, 255, 255));
        jpnTipoCliente.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tipo Cliente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        buttonGroup1.add(StxtBomCli);
        StxtBomCli.setText("Bom");
        StxtBomCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StxtBomCliActionPerformed(evt);
            }
        });

        buttonGroup1.add(StxtRegCli);
        StxtRegCli.setText("Regular");
        StxtRegCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StxtRegCliActionPerformed(evt);
            }
        });

        buttonGroup1.add(stxtRuimCli);
        stxtRuimCli.setText("Ruim");
        stxtRuimCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stxtRuimCliActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpnTipoClienteLayout = new javax.swing.GroupLayout(jpnTipoCliente);
        jpnTipoCliente.setLayout(jpnTipoClienteLayout);
        jpnTipoClienteLayout.setHorizontalGroup(
            jpnTipoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnTipoClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(StxtBomCli)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(StxtRegCli)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(stxtRuimCli)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jpnTipoClienteLayout.setVerticalGroup(
            jpnTipoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnTipoClienteLayout.createSequentialGroup()
                .addContainerGap(29, Short.MAX_VALUE)
                .addGroup(jpnTipoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(StxtBomCli)
                    .addComponent(StxtRegCli)
                    .addComponent(stxtRuimCli))
                .addGap(47, 47, 47))
        );

        lblDataCliente.setFont(new java.awt.Font("Arial", 1, 12));
        lblDataCliente.setText("Data");

        txtDataCadastroCliente.setFont(new java.awt.Font("Arial", 0, 12));
        txtDataCadastroCliente.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        Date data = new Date(System.currentTimeMillis());
        SimpleDateFormat formatarDate = new SimpleDateFormat("dd/MM/yyyy");/*
        */
        txtDataCadastroCliente.setText(formatarDate.format(data));
        txtDataCadastroCliente.setEditable(false);
        txtDataCadastroCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDataCadastroClienteActionPerformed(evt);
            }
        });

        btSalvarCli.setText("Salvar");
        btSalvarCli.setToolTipText("Salvar");
        btSalvarCli.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btSalvarCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarCliActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Observação", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        stxtObsCli.setColumns(20);
        stxtObsCli.setRows(5);
        stxtObsCli.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jScrollPane1.setViewportView(stxtObsCli);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 88, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel45.setBackground(new java.awt.Color(255, 255, 255));
        jPanel45.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Editar Veículo(s)", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        btCadasVeiCli.setText("Editar Veículo");
        btCadasVeiCli.setToolTipText("Editar Veículo(s)");
        btCadasVeiCli.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btCadasVeiCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCadasVeiCliActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel45Layout = new javax.swing.GroupLayout(jPanel45);
        jPanel45.setLayout(jPanel45Layout);
        jPanel45Layout.setHorizontalGroup(
            jPanel45Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel45Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(btCadasVeiCli)
                .addContainerGap(21, Short.MAX_VALUE))
        );
        jPanel45Layout.setVerticalGroup(
            jPanel45Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel45Layout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addComponent(btCadasVeiCli)
                .addContainerGap(28, Short.MAX_VALUE))
        );

        btSairEditarCli.setText("Sair");
        btSairEditarCli.setToolTipText("Sair");
        btSairEditarCli.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
        btSairEditarCli.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSairEditarCliActionPerformed(evt);
            }
        });

        jpnEnderecoCliente1.setBackground(new java.awt.Color(255, 255, 255));
        jpnEnderecoCliente1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Endereço", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12))); // NOI18N

        lblCepCliente1.setFont(new java.awt.Font("Arial", 1, 11));
        lblCepCliente1.setText("CEP");

        lblEstadoCliente1.setFont(new java.awt.Font("Arial", 1, 11));
        lblEstadoCliente1.setText("Estado ");

        lblCidadeCliente1.setFont(new java.awt.Font("Arial", 1, 11));
        lblCidadeCliente1.setText("Cidade ");

        cbCidade.setModel(new javax.swing.DefaultComboBoxModel(new String[] {null}));
        cbCidade.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        cbCidade.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbCidadeItemStateChanged(evt);
            }
        });

        lblBairroCliente1.setFont(new java.awt.Font("Arial", 1, 11));
        lblBairroCliente1.setText("Bairro ");

        cbBairro.setModel(new javax.swing.DefaultComboBoxModel(new String[] {""
        }));
        cbBairro.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        cbBairro.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbBairroItemStateChanged(evt);
            }
        });

        lblRuaAvCliente1.setFont(new java.awt.Font("Arial", 1, 11));
        lblRuaAvCliente1.setText("Rua/Av.");

        cbEndereco.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
            ""}));
cbEndereco.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
cbEndereco.addItemListener(new java.awt.event.ItemListener() {
    public void itemStateChanged(java.awt.event.ItemEvent evt) {
        cbEnderecoItemStateChanged(evt);
    }
    });

    lblNumeroCliente1.setFont(new java.awt.Font("Arial", 1, 11));
    lblNumeroCliente1.setText("Nº. ");

    ItxtNumCli.setFont(new java.awt.Font("Arial", 0, 12));
    ItxtNumCli.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    lblComplementoCliente1.setFont(new java.awt.Font("Arial", 1, 11));
    lblComplementoCliente1.setText("Complemento");

    cbEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] {}));
    cbEstado.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    cbEstado.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            cbEstadoItemStateChanged(evt);
        }
    });

    stxtApCli.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

    stxtCompCli.setModel(new javax.swing.DefaultComboBoxModel(new String[] { null, "CASA", "APARTAMENTO"}));
    stxtCompCli.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    stxtCompCli.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            stxtCompCliActionPerformed(evt);
        }
    });

    cbCep.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
    try {
        cbCep.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###-###")));
    } catch (java.text.ParseException ex) {
        ex.printStackTrace();
    }
    cbCep.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            cbCepActionPerformed(evt);
        }
    });

    jLabel1.setFont(new java.awt.Font("Arial", 1, 11));
    jLabel1.setText("Apartamento");

    jButton1.setText("Editar");
    jButton1.setToolTipText("Editar Endereço");
    jButton1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)));
    jButton1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jButton1ActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout jpnEnderecoCliente1Layout = new javax.swing.GroupLayout(jpnEnderecoCliente1);
    jpnEnderecoCliente1.setLayout(jpnEnderecoCliente1Layout);
    jpnEnderecoCliente1Layout.setHorizontalGroup(
        jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
            .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                    .addGap(644, 644, 644)
                    .addComponent(lblMensagemEndereco))
                .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                            .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                                    .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(cbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(lblEstadoCliente1))
                                    .addGap(18, 18, 18)
                                    .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(lblCidadeCliente1)
                                        .addComponent(cbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(18, 18, 18)
                                    .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                                            .addComponent(lblBairroCliente1)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnEnderecoCliente1Layout.createSequentialGroup()
                                            .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(cbBairro, 0, 234, Short.MAX_VALUE)
                                                .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                                                    .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(ItxtNumCli, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(lblNumeroCliente1))
                                                    .addGap(18, 18, 18)
                                                    .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(lblComplementoCliente1)
                                                        .addComponent(stxtCompCli, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                            .addGap(26, 26, 26))))
                                .addComponent(lblRuaAvCliente1)
                                .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                                    .addComponent(cbEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 373, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                            .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                                    .addGap(24, 24, 24)
                                    .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(lblCepCliente1)
                                        .addComponent(cbCep, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(stxtApCli, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
                                        .addComponent(jLabel1)))))
                        .addComponent(jButton1))))
            .addContainerGap())
    );
    jpnEnderecoCliente1Layout.setVerticalGroup(
        jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnEnderecoCliente1Layout.createSequentialGroup()
            .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                    .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                            .addComponent(lblEstadoCliente1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                            .addComponent(lblCidadeCliente1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                            .addComponent(lblBairroCliente1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cbBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                            .addComponent(lblRuaAvCliente1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cbEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                            .addGap(1, 1, 1)
                            .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(ItxtNumCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                                    .addGroup(jpnEnderecoCliente1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(lblComplementoCliente1)
                                        .addComponent(lblNumeroCliente1))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(stxtCompCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(stxtApCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                .addGroup(jpnEnderecoCliente1Layout.createSequentialGroup()
                    .addComponent(lblCepCliente1)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(cbCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
            .addComponent(jButton1)
            .addGap(17, 17, 17)
            .addComponent(lblMensagemEndereco))
    );

    javax.swing.GroupLayout jpnCadastroClienteLayout = new javax.swing.GroupLayout(jpnCadastroCliente);
    jpnCadastroCliente.setLayout(jpnCadastroClienteLayout);
    jpnCadastroClienteLayout.setHorizontalGroup(
        jpnCadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jpnCadastroClienteLayout.createSequentialGroup()
            .addGroup(jpnCadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jpnCadastroClienteLayout.createSequentialGroup()
                    .addGap(10, 10, 10)
                    .addComponent(lblDataCliente)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(txtDataCadastroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jpnCadastroClienteLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jpnTipoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jPanel45, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(jpnCadastroClienteLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(btSalvarCli)
                    .addGap(18, 18, 18)
                    .addComponent(btSairEditarCli))
                .addGroup(jpnCadastroClienteLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jpnCadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jpnEnderecoCliente1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jpnPessoalCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
            .addContainerGap())
    );

    jpnCadastroClienteLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btSairEditarCli, btSalvarCli});

    jpnCadastroClienteLayout.setVerticalGroup(
        jpnCadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jpnCadastroClienteLayout.createSequentialGroup()
            .addGroup(jpnCadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(lblDataCliente)
                .addComponent(txtDataCadastroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jpnPessoalCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jpnEnderecoCliente1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(jpnCadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jpnTipoCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel45, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGap(19, 19, 19)
            .addGroup(jpnCadastroClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(btSairEditarCli)
                .addComponent(btSalvarCli, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(23, 23, 23))
    );

    jpnCadastroClienteLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btSairEditarCli, btSalvarCli});

    javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jpnCadastroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 780, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );
    jPanel2Layout.setVerticalGroup(
        jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel2Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jpnCadastroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 576, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(19, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width-808)/2, (screenSize.height-627)/2, 808, 627);
    }// </editor-fold>//GEN-END:initComponents

    private void btSalvarCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarCliActionPerformed

        if (validar()) {//confirmando se a validação dos campos pelo metodo validação

            try {
                cli = new Cliente();
                cli.setNomePessoa(stxtNomeCli.getText().trim().toUpperCase());

                cli.setCpfPessoa(stxtCpfCli.getText().trim().toLowerCase());

                cli.setRgPessoa(stxtRgCli.getText().trim().toUpperCase());
                cli.setDataNascPessoa(stxtDataNascCli.getText());
                cli.setTelPessoa(stxtTelCli.getText().trim().toUpperCase());
                cli.setCelPessoa(stxtCelCli.getText().trim().toUpperCase());
                cli.setEmailPessoa(stxtEmailCli.getText().trim().toUpperCase());



                Endereco itemEnd = (Endereco) cbEndereco.getSelectedItem();


                cli.setNumPessoa(Integer.parseInt(ItxtNumCli.getText()));
                cli.setComplementoPessoa((String) stxtCompCli.getSelectedItem());

                cli.setApartPessoa(stxtApCli.getText().trim().toUpperCase());
                cli.setObservacao(stxtObsCli.getText().trim().toUpperCase());
                cli.setTipoCliente(selTipo);

                String sql = "update cliente set nome_cliente=?, cpf_cliente=?, rg_cliente=?,data_nasc_cliente=TO_DATE('" + cli.getDataNascPessoa() + "','DD/MM/YYYY'),tel_cliente=?,cel_cliente=?,email_cliente=?,num_cliente=?,complemento_cliente=?,apart_cliente=?,id_endereco=?,obs_cliente=?,tipo_cliente=? where id_cliente=?";

                Object[] parametros = {cli.getNomePessoa(), cli.getCpfPessoa(), cli.getRgPessoa(), cli.getTelPessoa(), cli.getCelPessoa(), cli.getEmailPessoa(), cli.getNumPessoa(), cli.getComplementoPessoa(), cli.getApartPessoa(), itemEnd.getIdEndereco(), cli.getObservacao(), cli.getTipoCliente(), idCli};
                Object[] tipos = {String.class, String.class, String.class, String.class, String.class, String.class, Integer.class, String.class, String.class, Integer.class, String.class, String.class, Integer.class};

                //String sql = "update cliente set nome_cliente=?, cpf_cliente=?,rg_cliente=?,data_nasc_cliente=?,tel_cliente=?,cel_cliente=?,email_cliente=?,num_cliente=?,complemento_cliente=?,apart_cliente=?,id_endereco=?,obs_cliente='',tipo_cliente=?  where id_cliente=?";
                //Object[] parametros = {cli.getNomePessoa(),cli.getCpfPessoa(),cli.getRgPessoa(),cli.getTelPessoa(),cli.getCelPessoa(),cli.getEmailPessoa(),cli.getNumPessoa(),cli.getComplementoPessoa(),cli.getApartPessoa(),itemEnd.getIdEndereco(),cli.getObservacao(),cli.getTipoCliente(),idCli};
                //Object[] tipos      = {String.class       ,String.class      ,String.class     ,String.class      ,String.class      ,String.class         ,Integer.class    ,String.class              ,String.class        ,Integer.class           ,String.class       ,String.class       ,Integer.class};


                BD banco = new BD();
                banco.executar(sql, parametros, tipos);

                JOptionPane.showMessageDialog(rootPane, "Atualização realizada com Sucesso");


            } catch (Exception ex) {
                ex.printStackTrace();

            }

        }
}//GEN-LAST:event_btSalvarCliActionPerformed

    private void txtDataCadastroClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDataCadastroClienteActionPerformed
}//GEN-LAST:event_txtDataCadastroClienteActionPerformed

    private void btCadasVeiCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCadasVeiCliActionPerformed
        // TODO add your handling code here:
        EditarVeiculo veiculo = new EditarVeiculo();
        veiculo.setVisible(true);
        veiculo.inicializarPF(stxtNomeCli.getText(), idCli);


    }//GEN-LAST:event_btCadasVeiCliActionPerformed

    private void StxtBomCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StxtBomCliActionPerformed

        Cliente cliente = new Cliente();
        if (StxtBomCli.isSelected()) {
            selTipo = "Bom";
            cliente.setTipoCliente(selTipo);
        }

    }//GEN-LAST:event_StxtBomCliActionPerformed

    private void StxtRegCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StxtRegCliActionPerformed

        Cliente cliente = new Cliente();
        if (StxtRegCli.isSelected()) {
            selTipo = "Regular";
            cliente.setTipoCliente(selTipo);
        }

    }//GEN-LAST:event_StxtRegCliActionPerformed

    private void stxtRuimCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stxtRuimCliActionPerformed

        Cliente cliente = new Cliente();
        if (stxtRuimCli.isSelected()) {
            selTipo = "Ruim";
            cliente.setTipoCliente(selTipo);
        }
    }//GEN-LAST:event_stxtRuimCliActionPerformed

    private void btSairEditarCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSairEditarCliActionPerformed
        this.dispose();

    }//GEN-LAST:event_btSairEditarCliActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        cbEstado.setEnabled(true);
        cbCidade.setEnabled(true);
        cbBairro.setEnabled(true);
        cbEndereco.setEnabled(true);
        ItxtNumCli.setEnabled(true);
        stxtCompCli.setEnabled(true);
        stxtApCli.setEnabled(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void cbCidadeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbCidadeItemStateChanged
        try {

            String sql;
            cbBairro.removeAllItems(); // limpa a caixa de cidades atual.
            if (cbCidade.getSelectedItem() != null) {
                Cidade itemcid = (Cidade) cbCidade.getSelectedItem();

                sql = "Select * from bairro where id_cidade = " + itemcid.getIdCidade() + " order by NOME_BAIRRO";


                BD bd = new BD();
                ResultSet r = bd.consultar(sql);

                Bairro bairro1 = new Bairro();
                cbBairro.addItem(bairro1);
                while (r.next()) {

                    Bairro bairro = new Bairro();

                    bairro.setIdBairro(r.getInt("id_bairro"));

                    String nomeBair = r.getString("NOME_BAIRRO");
                    bairro.setNomeBairro(nomeBair);


                    cbBairro.addItem(bairro);
                    if (bairro.getNomeBairro().equalsIgnoreCase(bai)) {
                        cbBairro.setSelectedItem(bairro);
                    }
                }
            }
        } catch (ClassNotFoundException ex) {
        } catch (SQLException ex) {
        }

    }//GEN-LAST:event_cbCidadeItemStateChanged

    private void cbBairroItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbBairroItemStateChanged

        try {

            String sql;
            cbEndereco.removeAllItems(); // limpa a caixa de cidades atual.
            if (cbBairro.getSelectedItem() != null) {
                Bairro itemBai = (Bairro) cbBairro.getSelectedItem();

                sql = "Select * from endereco where id_bairro = " + itemBai.getIdBairro() + "order by NOME_ENDERECO";


                BD bd = new BD();
                ResultSet r = bd.consultar(sql);

                Endereco end1 = new Endereco();
                cbEndereco.addItem(end1);

                while (r.next()) {


                    Endereco end = new Endereco();

                    end.setIdEndereco(r.getInt("id_endereco"));

                    end.setNomeEndereco(r.getString("NOME_ENDERECO"));

                    end.setCepEndereco(r.getString("cep"));

                    cbEndereco.addItem(end);
                    if (end.getNomeEndereco().equalsIgnoreCase(this.end)) {
                        cbEndereco.setSelectedItem(end);
                    }
                }
            }
        } catch (ClassNotFoundException ex) {
        } catch (SQLException ex) {
        }
    }//GEN-LAST:event_cbBairroItemStateChanged

    private void cbEnderecoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbEnderecoItemStateChanged

        if (cbEndereco.getSelectedItem() != null) {
            Endereco itemEnd = (Endereco) cbEndereco.getSelectedItem();

            cbCep.setText(itemEnd.getCepEndereco());
            cbCep.setEnabled(false);
        }
    }//GEN-LAST:event_cbEnderecoItemStateChanged

    private void cbEstadoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbEstadoItemStateChanged
        try {

            String sql;
            cbCidade.removeAllItems(); // limpa a caixa de cidades atual.

            if (cbEstado.getSelectedItem() != null) {
                Estado itemEst = (Estado) cbEstado.getSelectedItem();
                sql = "Select * from cidade where id_uf = '" + itemEst.getIdUf() + "' order by NOME_CIDADE";


                BD bd = new BD();
                ResultSet r = bd.consultar(sql);

                Cidade cidade1 = new Cidade();
                cbCidade.addItem(cidade1);
                while (r.next()) {
                    Cidade cidade = new Cidade();


                    cidade.setIdCidade(r.getInt("id_cidade"));

                    String nomeCid = r.getString("NOME_CIDADE");
                    cidade.setNomeCidade(nomeCid);

                    cbCidade.addItem(cidade);
                    if (cidade.getNomeCidade().equalsIgnoreCase(cid)) {
                        cbCidade.setSelectedItem(cidade);
                    }
                }
            }
        } catch (ClassNotFoundException ex) {
        } catch (SQLException ex) {
        }

    }//GEN-LAST:event_cbEstadoItemStateChanged

    private void stxtCompCliActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stxtCompCliActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_stxtCompCliActionPerformed

    private void cbCepActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbCepActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_cbCepActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    new EditarCliente().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(EditarCliente.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField ItxtNumCli;
    private javax.swing.JRadioButton StxtBomCli;
    private javax.swing.JRadioButton StxtRegCli;
    private javax.swing.JButton btCadasVeiCli;
    private javax.swing.JButton btSairEditarCli;
    private javax.swing.JButton btSalvarCli;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cbBairro;
    private javax.swing.JFormattedTextField cbCep;
    private javax.swing.JComboBox cbCidade;
    private javax.swing.JComboBox cbEndereco;
    private javax.swing.JComboBox cbEstado;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel45;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel jpnCadastroCliente;
    private javax.swing.JPanel jpnEnderecoCliente1;
    private javax.swing.JPanel jpnPessoalCliente;
    private javax.swing.JPanel jpnTipoCliente;
    private javax.swing.JLabel lblBairroCliente1;
    private javax.swing.JLabel lblCelularCliente;
    private javax.swing.JLabel lblCepCliente1;
    private javax.swing.JLabel lblCidadeCliente1;
    private javax.swing.JLabel lblComplementoCliente1;
    private javax.swing.JLabel lblCpfCliente;
    private javax.swing.JLabel lblDataCliente;
    private javax.swing.JLabel lblDataNascCliente;
    private javax.swing.JLabel lblEmailCliente;
    private javax.swing.JLabel lblEstadoCliente1;
    private javax.swing.JLabel lblMensagemEndereco;
    private javax.swing.JLabel lblNomeCliente;
    private javax.swing.JLabel lblNumeroCliente1;
    private javax.swing.JLabel lblRgCliente;
    private javax.swing.JLabel lblRuaAvCliente1;
    private javax.swing.JLabel lblTelefoneCliente;
    private javax.swing.JTextField stxtApCli;
    private javax.swing.JFormattedTextField stxtCelCli;
    private javax.swing.JComboBox stxtCompCli;
    private javax.swing.JFormattedTextField stxtCpfCli;
    private javax.swing.JFormattedTextField stxtDataNascCli;
    private javax.swing.JTextField stxtEmailCli;
    private javax.swing.JTextField stxtNomeCli;
    private javax.swing.JTextArea stxtObsCli;
    private javax.swing.JTextField stxtRgCli;
    private javax.swing.JRadioButton stxtRuimCli;
    private javax.swing.JFormattedTextField stxtTelCli;
    private javax.swing.JTextField txtDataCadastroCliente;
    // End of variables declaration//GEN-END:variables

    public void inicializar(int idcliente) {
        idCli = idcliente;
        iniciar();
    }

    ;
   public void iniciar() {

        //SALVADO O ID DO CLIENTE QUE VEIO DA TELA LOCALIZARCLIENTE.
        try {
            String sqlp = "SELECT * FROM CLIENTE WHERE ID_CLIENTE =" + idCli;
            BD bd2 = new BD();
            ResultSet r2 = bd2.consultar(sqlp);


            if (r2.next()) {
                stxtNomeCli.setText(r2.getString("NOME_CLIENTE"));
                stxtCpfCli.setText(r2.getString("CPF_CLIENTE"));
                stxtRgCli.setText(r2.getString("RG_CLIENTE"));

                stxtTelCli.setText(r2.getString("TEL_CLIENTE"));
                stxtCelCli.setText(r2.getString("CEL_CLIENTE"));
                stxtEmailCli.setText(r2.getString("EMAIL_CLIENTE"));
                ItxtNumCli.setText(r2.getString("NUM_CLIENTE"));
                stxtApCli.setText(r2.getString("APART_CLIENTE"));
                stxtObsCli.setText(r2.getString("OBS_CLIENTE"));

                stxtCompCli.setSelectedItem(r2.getString("COMPLEMENTO_CLIENTE"));


//---------------------------------formatando a data de nascimento---------------------------
                String data1 = r2.getString("DATA_NASC_CLIENTE");
                String dtFinal = "";
                if (data1 != null) {
                    String data = data1.split(" ")[0];  //corta a strin onde tem o espaço
                    String[] vData = data.split("-");//corta a onde tem "-"
                    String dia = vData[2];
                    String mes = vData[1];
                    String ano = vData[0];
                    dtFinal = dia + mes + ano;
                    stxtDataNascCli.setText(dtFinal);
                }

//---------------------------------fim da formatação da data--------------------------------
                if (r2.getString("TIPO_CLIENTE") != null) {
                    if (r2.getString("TIPO_CLIENTE").equalsIgnoreCase("Bom")) {
                        StxtBomCli.setSelected(true);
                        selTipo = "Bom";
                    } else if (r2.getString("TIPO_CLIENTE").equalsIgnoreCase("Regular")) {
                        StxtRegCli.setSelected(true);
                        selTipo = "Regular";
                    } else if (r2.getString("TIPO_CLIENTE").equalsIgnoreCase("Ruim")) {
                        stxtRuimCli.setSelected(true);
                        selTipo = "Ruim";
                    }
                }

            }


        } catch (ClassNotFoundException ex) {
        } catch (SQLException ex) {
        }
//-----------------------------------------------------------------------------------------------------------

//-----------------------PEGANDO O ENDERECO PARA PREENCHER O COMBO  -----------------------------------
        try {
            String sqlt = "SELECT E.ID_UF,CC.NOME_CIDADE,B.NOME_BAIRRO,EN.NOME_ENDERECO FROM CLIENTE CL "
                    + "INNER JOIN ENDERECO EN ON CL.ID_ENDERECO=EN.ID_ENDERECO "
                    + "INNER JOIN BAIRRO B ON B.ID_BAIRRO = EN.ID_BAIRRO "
                    + "INNER JOIN CIDADE CC ON CC.ID_CIDADE=B.ID_CIDADE "
                    + "INNER JOIN ESTADO E ON E.ID_UF=CC.ID_UF "
                    + "WHERE CL.ID_CLIENTE=" + idCli;
            BD bd2 = new BD();
            ResultSet r12;

            r12 = bd2.consultar(sqlt);

            if (r12.next()) {
                estad = r12.getString("ID_UF");
                cid = r12.getString("NOME_CIDADE");
                bai = r12.getString("NOME_BAIRRO");
                end = r12.getString("NOME_ENDERECO");
            }

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(EditarCliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(EditarCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
//-----------------------FIM DE PEGANDO O ENDERECO PARA PREENCHER O COMBO-----------------------------------


        //---------------------------PREENCHENDO O COMBO DE ESTADO O ENDERECO DO CLIENTE   --------------------------
        try {
            String sql = "Select * from estado order by id_uf";
            BD bd = new BD();
            ResultSet r1 = bd.consultar(sql);
            Estado est = new Estado();
            cbEstado.addItem(est);

            while (r1.next()) {
                estado = new Estado();
                String sigla = r1.getString("id_uf");
                // preenchendo informacoes do objeto
                estado.setIdUf(sigla);
                // e.setId(r1.getInt("id");
                cbEstado.addItem(estado);

                if (estado.getIdUf().equalsIgnoreCase(estad)) {
                    cbEstado.setSelectedItem(estado);
                }
            }


        } catch (ClassNotFoundException ex) {
        } catch (SQLException ex) {
        }

//---------------------------FIM PREENCHENDO O COMBO DE ESTADO O ENDERECO DO CLIENTE -------------------------
        cbEstado.setEnabled(false);
        cbCidade.setEnabled(false);
        cbBairro.setEnabled(false);
        cbEndereco.setEnabled(false);
        ItxtNumCli.setEnabled(false);
        stxtCompCli.setEnabled(false);
        stxtApCli.setEnabled(false);


    }

    public boolean validar() {
        boolean Resultado = true;
        //////////////////////////////////////////////////////////////////  

        if (validarObservacao(stxtObsCli.getText()) == false) {
            Resultado = false;
        } else if (validarNome(stxtNomeCli.getText()) == false) {
            Resultado = false;
        } else if (validarCpf(stxtCpfCli.getText()) == false) {
            Resultado = false;
        } else if (validarRG(stxtRgCli.getText()) == false) {
            Resultado = false;
        } else if (validarData(stxtDataNascCli.getText()) == false) {
            Resultado = false;
        } else if (validarTelefone(stxtTelCli.getText()) == false) {
            Resultado = false;
        } else if (validarTelefone(stxtCelCli.getText()) == false) {
            Resultado = false;
        } else if (validarEmail(stxtEmailCli.getText()) == false) {
            Resultado = false;
        } else if (cbCep.getText().trim().equals(".   -")) {
            Resultado = false;
            JOptionPane.showMessageDialog(stxtCompCli, "O campo Endereço é obrigatório!");
        } else if (validarNumero(ItxtNumCli.getText()) == false) {
            Resultado = false;
        } else if (stxtCompCli.getSelectedItem() == null) {
            Resultado = false;
            JOptionPane.showMessageDialog(stxtCompCli, "O campo Complemento é obrigatório");
        } else if (stxtApCli.getText().trim().length() > 0) {
            Resultado = validarSalaApart(stxtApCli.getText());
        }





        return Resultado;
    }
}
